package com.windoent.yugioh.adapter.city;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.windoent.yugioh.R;
import com.windoent.yugioh.help.db.City;

import java.util.ArrayList;
import java.util.List;


/**
 * @Author ：程序员小冰
 * @新浪微博 ：http://weibo.com/mcxiaobing
 * @GitHub: https://github.com/QQ986945193
 * @CSDN博客: http://blog.csdn.net/qq_21376985
 * @OsChina空间: https://my.oschina.net/mcxiaobing
 */
public class HotCityGridAdapter extends BaseAdapter {
    private Context mContext;
    private List<City> mCities;

    public HotCityGridAdapter(Context context) {
        this.mContext = context;
        mCities = new ArrayList<>();
        mCities.add(new City("110000",1,mContext.getString(R.string.string_beijing),"beijingshi","B"));
        mCities.add(new City("310000",774,mContext.getString(R.string.string_shanghai),"shanghaishi","S"));
        mCities.add(new City("440100",1907,mContext.getString(R.string.string_guangzhou),"guangzhoushi","G"));
        mCities.add(new City("440300",1930,mContext.getString(R.string.string_shenzhen),"shenzhenshi","S"));
        mCities.add(new City("330100",900,mContext.getString(R.string.string_hangzhou),"hangzhoushi","H"));
        mCities.add(new City("320100",791,mContext.getString(R.string.string_nanjing),"nanjingshi","N"));
        mCities.add(new City("120000",18,mContext.getString(R.string.string_tianjin),"tianjinshi","T"));
        mCities.add(new City("420100",1655,mContext.getString(R.string.string_wuhan),"wuhanshi","W"));
        mCities.add(new City("500000",2202,mContext.getString(R.string.string_chongqing),"chongqingshi","C"));
    }

    @Override
    public int getCount() {
        return mCities == null ? 0 : mCities.size();
    }

    @Override
    public City getItem(int position) {
        return mCities == null ? null : mCities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        HotCityViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_hot_city_gridview, parent, false);
            holder = new HotCityViewHolder();
            holder.name = (TextView) view.findViewById(R.id.tv_hot_city_name);
            view.setTag(holder);
        } else {
            holder = (HotCityViewHolder) view.getTag();
        }
        holder.name.setText(mCities.get(position).getName());
        return view;
    }

    public static class HotCityViewHolder {
        TextView name;
    }
}
